//
//  XDTabBarController.swift
//  weibo
//
//  Created by lucy on 2016/10/22.
//  Copyright © 2016年 com.huashengHuaSheng. All rights reserved.
//

import UIKit


class XDTabBarController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        let tabBar = XDTabBar()
        tabBar.closure = {
        
            print("我在监听中间按钮")
        }
        setValue(tabBar, forKey: "tabBar")
        
        
        //添加四个主要的标签控制器
        addChildViewController(vc:XDHomeController(),title:"首页",imaName:"tabbar_home")
        addChildViewController(vc:XDMessageController(),title:"消息",imaName:"tabbar_message_center")
        addChildViewController(vc:XDDiscoverController(),title:"发现",imaName:"tabbar_discover")
        addChildViewController(vc:XDProfileController(),title:"我的",imaName:"tabbar_profile")

    }
    

    //MARK-添加四个标签控制器的方法
    private func addChildViewController(vc:UIViewController,title:String,imaName:String){
        vc.title=title
        vc.tabBarItem.image = UIImage(named: imaName)
        
        //设置文字颜色
        vc.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName: THEMECOLOR], for: UIControlState.selected)
        
        //添加标签控制器的选择图片
        vc.tabBarItem.image = UIImage(named: imaName)
        vc.tabBarItem.selectedImage = UIImage(named: "\(imaName)_selected")?.withRenderingMode(UIImageRenderingMode.alwaysOriginal)
        
        let vcNav = XDNavigationController(rootViewController: vc)
        addChildViewController(vcNav)
        
    }
    

}



























